// SPDX-License-Identifier: GPL-2.0
/*
 * Copyright (c) Huawei Technologies Co., Ltd. 2023-2023.
 * Description: KVM: arm64:vgic-v3: support virq set affinity to phys cpu
 */

struct kvm_vcpu *ite_get_vcpu(struct kvm *kvm, struct vgic_its *its,
			      u32 devid, u32 eventid)
{
	struct kvm_vcpu *vcpu;
	struct its_ite *ite;

	if (!its->enabled)
		return NULL;

	ite = find_ite(its, devid, eventid);
	if (!ite || !its_is_collection_mapped(ite->collection))
		return NULL;

	vcpu = kvm_get_vcpu(kvm, ite->collection->target_addr);
	if (!vcpu)
		return NULL;

	if (!vcpu->arch.vgic_cpu.lpis_enabled)
		return NULL;

	return vcpu;
}

int ite_get_irq(struct kvm *kvm, struct vgic_its *its,
		u32 devid, u32 eventid, struct vgic_irq **irq)
{
	struct its_ite *ite;

	if (!its->enabled)
		return -EBUSY;

	ite = find_ite(its, devid, eventid);
	if (!ite || !its_is_collection_mapped(ite->collection))
		return E_ITS_INT_UNMAPPED_INTERRUPT;

	*irq = ite->irq;

	return 0;
}

